﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CuteEditor;
using Wjtour.Domain;
using Wjtour.BLL;
using Hjp.FrameWork.Common;

namespace Wjtour.Web.Admin.suggestion
{
    public partial class addedi : BasePage
    {
        protected DropDownList cid;
        protected TextBox name;
        protected TextBox phone;
        protected TextBox email;
        protected TextBox content;
        protected TextBox replayer;
        protected TextBox replaycontent;
        protected TextBox replaytime;
        protected Button submit;

        protected int id = 0;
        Wjtour.Domain.suggestion entity = new Domain.suggestion();
        suggestion_bll _bll = new suggestion_bll();

        protected void Page_Load(object sender, EventArgs e)
        {
            id = Utils.StrToInt(Request["id"], 0);
            submit.Click += new EventHandler(submit_Click);
            if (id > 0)
            {
                entity = _bll.Load(id);
                if (!IsPostBack)
                {
                    if (entity != null)
                    {
                        name.Text = entity.name;
                        phone.Text = entity.phone;
                        email.Text = entity.email;
                        content.Text = entity.content;
                        replayer.Text = entity.replayer;
                        replaycontent.Text = entity.replaycontent;
                        replaytime.Text = entity.replaytime.HasValue ?
                            entity.replaytime.Value.ToString("yyyy-MM-dd HH:mm:ss")
                            : DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    }
                }

            }
            else
            {
                replayer.Text = CurrentUser.adminname;
                replaytime.Text =  DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            }
        }

        void submit_Click(object sender, EventArgs e)
        {
            entity.id = id;
            entity.name = name.Text;
            entity.phone = phone.Text;
            entity.email = email.Text;
            entity.content = content.Text;
            entity.replayer = replayer.Text;
            entity.replaycontent = replaycontent.Text;
            entity.replaytime = DateTime.Now;

            bool b = _bll.Save(entity);
            if (b)
            {
                Utils.Alert(this.Page, "保存成功！");
                Utils.Redirect(this.Page, "list.aspx", false);
            }

        }
    }
}